import util from '@/util'

const tags = {
    state: {
        tagslist: util.getStore({ name: 'tagslist' }) || []
    },
    actions: {

    },
    mutations: {
        // 设置标签
        SET_TAGSLIST(state, route) {
            const isExist = state.tagslist.some((item) => {
                return item.path === route.path;
            });
            !isExist &&
                state.tagslist.push({
                    title: route.name,
                    path: route.path,
                }) &&
                util.setStore({ name: 'tagslist', content: state.tagslist, type: 'session' })
        },
        // 关闭单个标签
        CLOSE_TAG(state, index) {
            state.tagslist.splice(index, 1);
            util.setStore({ name: 'tagslist', content: state.tagslist, type: 'session' })
        },
        // 关闭所有标签
        CLOSE_ALL(state) {
            state.tagslist = [];
            util.removeStore({
                name: 'tagslist',
                type: 'session'
            });
        },
        // 关闭其他标签
        CLOSE_OTHER(state, tag) {
            state.tagslist = tag;
            util.setStore({ name: 'tagslist', content: state.tagslist, type: 'session' })
        }
    },
}
export default tags